package com.icepuppet.mapper;

import com.icepuppet.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    //删除
    @Delete("delete from emp where id = #{id}")
    public void empDelete(Integer id);

    //添加
    @Insert("insert into emp (username, name, gender, image, job, entrydate, " +
            "dept_id,create_time, update_time) value" +
            "(#{username},#{name},#{gender},#{image},#{job},#{entryDate},#{deptId},#{createTime},#{updateTime});")
    public void empInsert(Emp emp);

    //更新
    @Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +
            "job = #{job}, entrydate = #{entryDate}, dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")
    public void empUpdate(Emp emp);

    //查询
    @Select("select * from emp where id = #{id}")
    public Emp empSelectByID(Integer id);

    //查询起别名
//    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id deptId," +
//            "create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp empSelectByID(Integer id);

    //查询Result
//    @Results({
//            @Result(column = "dept_id",property = "deptId"),
//            @Result(column = "create_time",property = "createTime"),
//            @Result(column = "update_time",property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp empSelectByID(Integer id);

    //条件查询

//    @Select("select * from emp where name like '%${name}%' and gender = #{gender} " +
//            "and entrydate between #{begin} and #{end} order by update_time desc")
//    public List<Emp> empSelectList(@Param("name") String name, @Param("gender") Short gender,
//                                   @Param("begin") LocalDate begin,@Param("end") LocalDate end);

//    @Select("select * from emp where name like concat('%',#{name},'%') and gender = #{gender} " +
//            "and entrydate between #{begin} and #{end} order by update_time desc")
    public List<Emp> empSelectList(@Param("name") String name, @Param("gender") Short gender,
                                   @Param("begin") LocalDate begin,@Param("end") LocalDate end);

    //动态更新
    public void empUpdate2(Emp emp);

    //批量删除
    public void empDeleteByIds(@Param("ids") List<Integer> ids);
}
